# 顺序查找
from cal_time import *
@cal_time
def lines_search(li, value):
    for index, val in enumerate(li):
        if val == value:
            print(index)
            return index
    else:
        return None

# @cal_time
# def binary_search(li, value):
#     left = 0
#     right = len(li)-1
#     while left <= right:
#         mid = (left + right) // 2
#         if li[mid] == value:
#             print(mid)
#             return mid
#         elif li[mid] > value:
#             right = mid -1
#         elif li[mid] < value:
#             left = mid + 1
#     else:
#         return None
#


def binary_search(li, val):
    left = 0
    right = len(li) - 1

    while left <= right:
        mid = (left + right) // 2
        if val == li[mid]:
            return mid
        elif val < li[mid]:
            right = mid -1
        else:
            left = mid + 1
    else:
        return None


print(binary_search([1, 2, 3, 4, 5, 6, 7, 8, 9], 4))
